package ae.pcfc.cldos.online.web.util;

import java.beans.PropertyEditorSupport;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.web.util.HtmlUtils;

public class StringEscapeEditor extends PropertyEditorSupport {

	private boolean escapeHTML;
	
	private boolean escapeJavaScript;
	
	private boolean escapeSQL;
	
	public StringEscapeEditor() {
	        super();
	}
	
	public StringEscapeEditor(boolean escapeHTML, boolean escapeJavaScript,
	                boolean escapeSQL) {
	        super();
	        this.escapeHTML = escapeHTML;
	        this.escapeJavaScript = escapeJavaScript;
	        this.escapeSQL = escapeSQL;
	}
	
	public void setAsText(String text) {
	        if (text == null) {
	                setValue(null);
	        } else {
	                String value = text;
	                if (escapeHTML) {
	                        //value = HtmlUtils.htmlEscape(value);
	                        //value = StringEscapeUtils.escapeHtml(value);
	                }
	                if (escapeJavaScript) {
	                        //value = StringEscapeUtils.escapeJavaScript(value);
	                }
	                if (escapeSQL) {
	                        //value = StringEscapeUtils.escapeSql(value);
	                }
	                setValue(value);
	        }
	}
	
	public String getAsText() {
	        Object value = getValue();
	        return (value != null ? value.toString() : "");
	}

}
